package no.knowit.components;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;

/**
 * Layout component for pages of application mapIT.
 */
@IncludeStylesheet("context:layout/layout.css")
public class Layout {
	/** The page title, for the <title> element and the <h1>element. */
	@Property
	@Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
	private String title;

	@Property
	private String pageName;

	@Property
	@Parameter(defaultPrefix = BindingConstants.LITERAL)
	private String sidebarTitle;

	@Property
	@Parameter(defaultPrefix = BindingConstants.LITERAL)
	private Block sidebar;

	@Inject
	private ComponentResources resources;

	@Inject
	private Messages messages;

	public String getClassForPageName() {
		String classForPageName = null;
		if (resources.getPageName().equalsIgnoreCase(pageName)) {
			classForPageName = "current_page_item";
		}
		return classForPageName;
	}

	public String[] getPageNames() {
		return new String[] { "Index", "prosjekt/NyttProsjekt",
				"oppdragsgiver/NyOppdragsgiver", "ressurs/NyRessurs" };
	}

	public String getLocalizedName(String pageName) {
		return messages.get("sidenavn." + pageName);
	}
}
